package ExerChapter15Collection_;

import java.util.ArrayList;
import java.util.List;

public class OrderList {

    public static void main(String[] args) {
        List<Book> list = new ArrayList<>();
        list.add(new Book("A", "a", 4));
        list.add(new Book("B", "b", 3));
        list.add(new Book("C", "c", 2));
        list.add(new Book("D", "d", 1));

        System.out.println(list);
// 冒泡排序
        for (int i = 0;i < list.size()-1;i++){
            for(int j = 0;j < list.size() - 1 -i;j++){
                Book temp = list.get(j);
                list.set(j, list.get(j + 1));
                list.set(j + 1, temp);
            }
        }
        System.out.println("***************排序后****************");
        System.out.println(list);
    }

}

class Book{
    public String name;
    public String author;
    public double price;

    public Book(String name, String author, double price) {
        this.name = name;
        this.author = author;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book [name=" + name + ", author=" + author + ", price=" + price + "]";
    }

    public double getPrice() {
        return price;
    }
}